//
//  MainViewDataModel.m
//  QRMaster
//  mainView的数据处理
//  Created by myApple on 16/5/10.
//  Copyright © 2016年 myApple. All rights reserved.
//

#import "MainViewDataModel.h"
#import "CardInfoModel.h"
#import "CardInfoTableViewCell.h"
#import "SelectRoomViewController.h"
#import "BulidingModel.h"
#import "FloorsModel.h"
#import "roomsModel.h"
#import "faveriterCard.h"
#import "BackTableViewCell.h"
#import "RoomTimeController.h"
#import "StartPageController.h"
#import "checkPower.h"
#import "BulidingInfoLogic.h"
#import "FloorsInfoLogic.h"
#import "RoomInfoLogic.h"

@implementation MainViewDataModel


#pragma mark----------------- 房卡的存储
-(void)insertDataIntoRooms:(NSArray *)allBuildingInfo
{
    BulidingInfoLogic * bulidingDataBase = [[BulidingInfoLogic alloc]init];
    FloorsInfoLogic * floorDataBase = [[FloorsInfoLogic alloc]init];
    RoomInfoLogic * roomDataBase = [[RoomInfoLogic alloc]init];
    for (NSDictionary * bDict in allBuildingInfo)
    {
        BulidingModel * bModel = [[BulidingModel alloc]init];
        bModel.buildingName = [bDict objectForKey:@"buildingname"];
        bModel.buildingId = [bDict objectForKey:@"buildingid"];
        bModel.buildingNo = [bDict objectForKey:@"buildingno"];
        [bulidingDataBase insertBulidingInfo:bModel withCommunityId:[QRSingleton sharedQRSingleton].communityId];
        bModel.floors = [bDict objectForKey:@"floors"];
        for (NSDictionary * fDict in bModel.floors) {
            FloorsModel * fModel = [[FloorsModel alloc]init];
            fModel.floorId = [fDict objectForKey:@"floorid"];
            fModel.floorName = [fDict objectForKey:@"floorname"];
            fModel.floorNo  = [fDict objectForKey:@"floorno"];
            [floorDataBase insertFloorInfo:fModel withCommunityId:[QRSingleton sharedQRSingleton].communityId buildingId:bModel.buildingId];
            fModel.rooms = [fDict objectForKey:@"rooms"];
            for (NSDictionary * rDict in fModel.rooms) {
                RoomsModel * rModel = [[RoomsModel alloc]init];
                rModel.roomId = [rDict objectForKey:@"roomid"];
                rModel.roomName = [rDict objectForKey:@"roomname"];
                rModel.roomNo = [rDict objectForKey:@"roomno"];
                rModel.isSelect = [rDict objectForKey:@"isSelected"];
                rModel.lockNo = [rDict objectForKey:@"lockno"];
                rModel.occupation = [rDict objectForKey:@"occupation"];
                [roomDataBase insertRoomInfo:rModel withFloorId:fModel.floorId withCommunityId:[QRSingleton sharedQRSingleton].communityId];
            }
        }
    }
}


#pragma mark ----------从本地获取
//-(void)analysisHouseData:(NSArray *)data powerCard:(NSArray *)powerArray
//{
//    NSMutableArray * mainArray = [[NSMutableArray alloc]init];
//    for (NSDictionary * dict in data) {
//        for (NSDictionary * powerDict in powerArray) {
//            if ([[powerDict objectForKey:@"enable"]integerValue] == 1 && ) {
//                <#statements#>
//            }
//        }
//    }
//    if (data.count > 0 && [bulidingId isEqualToString:@""])
//    {
//        BulidingModel * bModel = [[BulidingModel alloc]init];
//        NSDictionary * bDict = data[0];
//        bModel.buildingId = [bDict objectForKey:@"buildingid"];
//        bModel.buildingName = [bDict objectForKey:@"buildingname"];
//        bModel.floors = [bDict objectForKey:@"floors"];
//        bulidingName = bModel.buildingName;
//        bulidingId = bModel.buildingId;
//        FloorsModel * fModel = [[FloorsModel alloc]init];
//        NSDictionary * fDict = bModel.floors[0];
//        fModel.floorId = [fDict objectForKey:@"floorid"];
//        fModel.floorName = [fDict objectForKey:@"floorname"];
//        fModel.rooms = [fDict objectForKey:@"rooms"];
//        floorId = fModel.floorId;
//        floorName = fModel.floorName;
//        for (NSDictionary * rDict in fModel.rooms) {
//            RoomsModel * rModel = [[RoomsModel alloc]init];
//            rModel.roomId = [rDict objectForKey:@"roomid"];
//            rModel.roomName = [rDict objectForKey:@"roomname"];
//            rModel.occupation = [rDict objectForKey:@"occupation"];
//            rModel.lockNo = [rDict objectForKey:@"lockNo"];
//            rModel.isSelect = [rDict objectForKey:@"isSelect"];
//            rModel.roomNo = [rDict objectForKey:@"roomNo"];
//            CardInfoModel * cardModel = [[CardInfoModel alloc]init];
//            cardModel.bulidingName = bulidingName;
//            cardModel.bulidingId = bulidingId;
//            cardModel.floorName = floorName;
//            cardModel.floorId = floorId;
//            cardModel.roomName = rModel.roomName;
//            cardModel.roomId = rModel.roomId;
//            cardModel.cardStyle = 2;
//            [cardInfoMutArray addObject:cardModel];
//        }
//        
//    }
//    else if(data.count > 0 && ![bulidingId isEqualToString:@""])
//    {
//        for (NSDictionary * bDict in data) {
//            if ([bulidingId isEqualToString:[bDict objectForKey:@"buildingid"]]) {
//                BulidingModel * bModel = [[BulidingModel alloc]init];
//                bModel.buildingName = [bDict objectForKey:@"buildingname"];
//                bModel.floors = [bDict objectForKey:@"floors"];
//                bulidingName = bModel.buildingName;
//                for (NSDictionary * fDict in bModel.floors) {
//                    if ([floorId isEqualToString:[fDict objectForKey:@"floorid"]]) {
//                        FloorsModel * fModel = [[FloorsModel alloc]init];
//                        fModel.floorName = [fDict objectForKey:@"floorname"];
//                        fModel.rooms = [fDict objectForKey:@"rooms"];
//                        floorName = fModel.floorName;
//                        for (NSDictionary * rDict in fModel.rooms) {
//                            RoomsModel * rModel = [[RoomsModel alloc]init];
//                            rModel.roomId = [rDict objectForKey:@"roomid"];
//                            rModel.roomName = [rDict objectForKey:@"roomname"];
//                            rModel.occupation = [rDict objectForKey:@"occupation"];
//                            rModel.lockNo = [rDict objectForKey:@"lockNo"];
//                            rModel.isSelect = [rDict objectForKey:@"isSelect"];
//                            rModel.roomNo = [rDict objectForKey:@"roomNo"];
//                            CardInfoModel * cardModel = [[CardInfoModel alloc]init];
//                            cardModel.bulidingName = bulidingName;
//                            cardModel.bulidingId = bulidingId;
//                            cardModel.floorName = floorName;
//                            cardModel.floorId = floorId;
//                            cardModel.roomName = rModel.roomName;
//                            cardModel.roomId = rModel.roomId;
//                            cardModel.cardStyle = 2;
//                            [cardInfoMutArray addObject:cardModel];
//                        }
//                    }
//                }
//            }
//        }
//    }
//}


@end
